package com.huluobo.a2308douyindemo.net

import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.sql.Time
import java.util.concurrent.TimeUnit

/**
 *  Created by LC on 2025/10/16.
 */

//懒加载HttpClient
private val client by lazy {
    OkHttpClient.Builder()
        .connectTimeout(30, TimeUnit.SECONDS)
        .readTimeout(30, TimeUnit.SECONDS)
        .writeTimeout(30, TimeUnit.SECONDS)
        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        .addInterceptor(TokenInterceptor())
        .build()
}

private val client7012 by lazy {
    OkHttpClient.Builder()
        .connectTimeout(30, TimeUnit.SECONDS)
        .readTimeout(30, TimeUnit.SECONDS)
        .writeTimeout(30, TimeUnit.SECONDS)
        .addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
        .addInterceptor(Token7012interceptor())
        .build()
}

private val retrofit by lazy {
    Retrofit.Builder()
        .baseUrl(Const.BASE_URL)
        .client(client)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}

private val giftRetrofit by lazy {
    Retrofit.Builder()
        .baseUrl(Const.GIFT_BASE_URL)
        .client(client7012)
        .addConverterFactory(GsonConverterFactory.create())
        .build()
}

fun getService() = retrofit.create(ApiService::class.java)

fun getGiftService() = giftRetrofit.create(ApiServiceGift::class.java)